﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:v="urn:schemas-microsoft-com:vml"	>
  <xsl:output method="html"  version="1.0" encoding="utf-8"/>

  <xsl:template match="/Process">
    <table>
      <tr VALIGN="top">
        <xsl:call-template name="InitStep" />
        <xsl:call-template name="Steps" />
        <xsl:call-template name="EndStep" />
      </tr>
    </table>
  </xsl:template>

  <xsl:template name="InitStep">
    <td>
      <xsl:call-template name="CreateGraph" >
        <xsl:with-param name="steptype" select="-1" />
        <xsl:with-param name="stepname" select="'发起'" />
        <xsl:with-param name="exheight" select="100" />
      </xsl:call-template>
    </td>
    <td>
      <xsl:call-template name="CreateArrow" />
    </td>
  </xsl:template>


  <xsl:template name="Steps">
    <xsl:for-each select="/Process/Steps/Step">
      <td>
        <xsl:call-template name="CreateGraph" >
          <xsl:with-param name="steptype" select="Attributes/StepType" />
          <xsl:with-param name="stepname" select="Attributes/Name" />
          <xsl:with-param name="exheight" select="count(Nodes/Node) * 24 + 100 - 24" />
          <xsl:with-param name="steppos" select="position()" />
        </xsl:call-template>
      </td>

      <xsl:if  test="following-sibling::Step[1]/Attributes/StepType=0 or Attributes/StepType=0 or boolean(following-sibling::Step)=false">
        <td>
          <xsl:call-template name="CreateArrow" />
        </td>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>



  <xsl:template name="EndStep">
    <td>
      <xsl:call-template name="CreateGraph" >
        <xsl:with-param name="steptype" select="2" />
        <xsl:with-param name="stepname" select="'结束'" />
        <xsl:with-param name="exheight" select="100" />
      </xsl:call-template>
    </td>
  </xsl:template>


  <xsl:template name="CreateGraph">
    <xsl:param name="stepid" />
    <xsl:param name="steptype" />
    <xsl:param name="stepname" />
    <xsl:param name="exheight" />
    <xsl:param name="steppos" />


    <xsl:element name="v:roundrect" use-attribute-sets="steprect">
      <xsl:attribute name="style">
        width:130px;text-align:left;height:<xsl:value-of select="$exheight" />px;
      </xsl:attribute>
      <xsl:if test="$steptype = 0 or $steptype = 1">
        <xsl:choose>
          <xsl:when test="sum(Nodes/Node/Attributes/IsActive)=0">
            <xsl:attribute name="fillcolor">#dddddd</xsl:attribute>
          </xsl:when>
          <xsl:when test="sum(Nodes/Node/Attributes/IsActive)>0 and 2 * count(Nodes/Node)>sum(Nodes/Node/Attributes/IsActive)">
            <xsl:attribute name="fillcolor">#ffcc66</xsl:attribute>
          </xsl:when>
          <xsl:when test="sum(Nodes/Node/Attributes/IsActive)=2 * count(Nodes/Node)">
            <xsl:attribute name="fillcolor">#dddddd</xsl:attribute>
          </xsl:when>
        </xsl:choose>
      </xsl:if>
      <v:fill type="gradient" opacity="80%" color2="white"/>
      <v:Textbox inset="3pt,3pt,0pt,0pt">
        <table class="wfgraph_step">
          <tr>
            <td>
              <span style="font:bolder">
                <xsl:choose>
                  <xsl:when test="$steptype=-1">
                    <img src="../Images/initstep.gif" />起点
                  </xsl:when>
                  <xsl:when test="$steptype=0">
                    <img src="../Images/sp.gif" />审批
                  </xsl:when>
                  <xsl:when test="$steptype=1">
                    <img src="../Images/hq.gif" />汇签
                  </xsl:when>
                  <xsl:when test="$steptype=2">
                    <img src="../Images/endstep.gif" />终点
                  </xsl:when>
                </xsl:choose>
              </span>
            </td>
            <td width="50" >
              <xsl:choose>
                <xsl:when test="sum(Nodes/Node/Attributes/IsActive)=2 * count(Nodes/Node)">
                  <xsl:choose>
                    <xsl:when test="$steptype=0">
                      <xsl:choose>
                        <xsl:when test="sum(Nodes/Node/Attributes/Value) >=number(Attributes/ThresholdValue)">
                          <span style="width:100%;font:bolder;color:green">通过</span>
                        </xsl:when>
                        <xsl:when test="sum(Nodes/Node/Attributes/PassValue)=-1">
                          <span style="width:100%;font:bolder;color:red">终止</span>
                        </xsl:when>
                        <xsl:when test="(2 * count(Nodes/Node)=sum(Nodes/Node/Attributes/IsActive)) and (number(Attributes/ThresholdValue) > sum(Nodes/Node/Attributes/Value))">
                          <xsl:choose>
                            <xsl:when test="Nodes/Node[1]/Attributes/AuditingDatetime='1'">
                              <span style="width:100%;font:bolder;color:red">不通过</span>
                            </xsl:when>
                            <xsl:otherwise>
                              <span style="width:100%;font:bolder;color:red">终止</span>
                            </xsl:otherwise>
                          </xsl:choose>

                        </xsl:when>
                      </xsl:choose>
                    </xsl:when>
                    <xsl:when test="$steptype=1">
                      <xsl:choose>
                        <xsl:when test="count(Nodes/Node) = sum(Nodes/Node/Attributes/AuditingDatetime)">
                          <span style="width:100%;font:bolder;color:green">完成</span>
                        </xsl:when>
                        <xsl:otherwise>
                          <span style="width:100%;font:bolder;color:red">终止</span>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="sum(Nodes/Node/Attributes/IsActive)=0">
                  <span style="width:100%;font:bolder;color:blue">未激活</span>
                </xsl:when>
                <xsl:when test="sum(Nodes/Node/Attributes/IsActive)>0 and 2 * count(Nodes/Node)>sum(Nodes/Node/Attributes/IsActive)">
                  <span style="width:100%;font:bolder;color:orange">处理中</span>
                </xsl:when>
              </xsl:choose>
            </td>
          </tr>
          <tr>
            <td colspan="2" height="15px">
              <xsl:value-of select="$stepname" />
            </td>
          </tr>
        </table>
        <hr/>
        <xsl:choose>
          <xsl:when test="$steptype=-1">
            <xsl:call-template name="InitMember" />
          </xsl:when>
          <xsl:when test="$steptype=2">
            <xsl:call-template name="EndMember" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="StepsMember" >
              <xsl:with-param name="steppos" select="$steppos" />
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </v:Textbox>
    </xsl:element >
  </xsl:template>


  <xsl:template name="InitMember">
    <table class="wfgraph_step" >
      <tr>
        <td width="20">
          <img src="../Images/member.gif" />
        </td>
        <td>
          <xsl:value-of select="/Process/Init-Step/Attributes/InitMemberName" />
        </td>
        <td></td>
      </tr>
    </table>
  </xsl:template>


  <xsl:template name="StepsMember">
    <xsl:param name="steppos" />
    <table class="wfgraph_step" >
      <xsl:for-each select="/Process/Steps/Step[$steppos]/Nodes/Node">
        <tr>
          <td width="20">
            <img src="../Images/member.gif" />
          </td>
          <td>
            <xsl:value-of select="Attributes/AuditorName" />
          </td>
          <td>
            <xsl:if test="Attributes/AuditingDatetime='1'">
              <xsl:choose>
                <xsl:when test="/Process/Steps/Step[$steppos]/Attributes/StepType=0" >
                  <xsl:choose>
                    <xsl:when test="Attributes/IsActive = 2">
                      <xsl:choose>
                        <xsl:when test="Attributes/PassValue = 1">同意</xsl:when>
                        <xsl:when test="Attributes/PassValue = 0">反对</xsl:when>
                        <xsl:when test="Attributes/PassValue = -1">作废</xsl:when>
                      </xsl:choose>
                    </xsl:when>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="/Process/Steps/Step[$steppos]/Attributes/StepType=1">
                  <xsl:if test="Attributes/IsActive=2 ">完成</xsl:if>
                </xsl:when>
              </xsl:choose>
            </xsl:if>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>


  <xsl:template name="EndMember">
    <table class="wfgraph_step" >
      <tr>
        <td width="20">
          <img src="../Images/member.gif" />
        </td>
        <td>
          <xsl:value-of select="/Process/End-Step/Attributes/BookMemberName" />
        </td>
        <td></td>
      </tr>
    </table>
  </xsl:template>


  <xsl:template name="CreateArrow">
    <br/>
    <br/>
    <v:line style="position:relative" from="0,0" to="30,0" >
      <v:stroke EndArrow="Classic"/>
    </v:line>
  </xsl:template>

  <xsl:attribute-set name="steprect">
    <xsl:attribute name="arcsize">5%</xsl:attribute>
    <xsl:attribute name="fillcolor">#dddddd</xsl:attribute>
    <xsl:attribute name="strokecolor">#dddddd</xsl:attribute>
    <xsl:attribute name="strokeweight">1px</xsl:attribute>
  </xsl:attribute-set>

</xsl:stylesheet>
